//请实现一个函数，把字符串 s 中的每个空格替换成"%20"。 
//
// 
//
// 示例 1： 
//
// 输入：s = "We are happy."
//输出："We%20are%20happy." 
//
// 
//
// 限制： 
//
// 0 <= s 的长度 <= 10000 
// 👍 51 👎 0

package leetcode.editor.cn;
//Java：替换空格
public class TiHuanKongGeLcof{
    public static void main(String[] args) {
        Solution solution = new TiHuanKongGeLcof().new Solution();
        String test = new String();
        solution.replaceSpace(test);
    }
    
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String replaceSpace(String s) {
        if ( s == null ){
            return s;
        }
        //计算有多少个空格
        int s_length = s.length();
        char[] new_char_array = new char[ s_length*3 ];
        int size = 0;
        for (int i = 0; i < s_length ; i++) {
            char now_char = s.charAt(i);
            if ( now_char == ' ' ){
                new_char_array[size++] = '%';
                new_char_array[size++] = '2';
                new_char_array[size++] = '0';
            }
            else {
                new_char_array[size++] = now_char;
            }
        }
        String answer_string = new String(new_char_array,0, size);
        return answer_string;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
